<?php
class specialController extends adminController{
    protected $layout = 'layout';
    //分类首页
    public function index(){
        $act = in($_GET['act']);
        if($act == 'del'){
            $fid = intval($_GET['id']);
            $result =  model('special')->del($fid);
            if($result){
                echo 1;
            }else{
                echo '删除失败!请查看是否包含子类';
            } 
        }else{
            $this->pid = intval($_GET['id']);  //当前ID
            $listRows = 20;
            $url = url('special/index',array('page'=>'{page}'));
            $allcount = model('special')->count('pid='.$this->pid);
            $limit = $this->pageLimit($url,$listRows);
            $this->page= $this->pageShow($allcount);
            $this->list = model('special')->select('pid='.$this->pid,null,null,$limit); 
            $this->path = model('special')->flpath($this->pid,'special/index');
            $this->display('special/index');
        }
    }
    //添加特性
    public function add(){
        if($this->isPost()){
            $msg = Check::rule(
                    array(check::must($_POST['name']),'特性名称必须填写'),
                    array(check::must($_POST['tpl_list']),'特性模板必须填写')
                    );
            if(true !== $msg){
                $this->jsonMsg($msg);
            }
            //插入模型数据
            $_POST['uptime'] = time();
            $data = array();
            $data = postinput($_POST,array('fid'));
            $info = model('special')->add($data);
            if($info){
                $this->jsonMsg('资源特性添加成功',1);
            }else{
                $this->jsonMsg('资源特性添加失败');
            }
        }else{
            $this->pid =intval($_GET['id']);
            $this->path = model('special')->flpath($this->pid);
            if($this->pid){
                $this->list = model('special')->find('id='.$this->pid,'cid');
            }else{
                $this->list = model('channel')->RootClass();
            }
            $this->display('special/add');
        } 
    }
    //编辑分类
    public function edit(){
        if($this->isPost()){
            $msg = Check::rule(
                    array(check::must($_POST['name']),'特性名称必须填写'),
                    array(check::must($_POST['tpl_list']),'特性模板必须填写')
                    );
            if(true !== $msg){
                $this->jsonMsg($msg);
            }
            $fid = intval($_POST['fid']);
            $_POST['uptime'] = time();
            $data = postinput($_POST,array('fid'));
            $info = model('special')->edit($fid,$data); //插入模型数据
            if($info){
                $this->jsonMsg('资源特性编辑成功',1);
            }else{
                $this->jsonMsg('资源特性编辑失败');
            }
        }else{
            $this->fid = intval($_GET['id']);
            $this->info = model('special')->find('id = '. $this->fid);
            $this->path = model('special')->flpath( $this->fid);
            $this->display('special/edit'); 
        }
    }
    
}